package com.bric.service;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import com.bric.util.MyProperties;

public class SendMsg {
	private static final String fgwWebServiceUrl=MyProperties.loadProperty("/chinaBric.properties").getProperty("fgwWebServiceUrl");
	private static final String fgwSendMailMethodName=MyProperties.loadProperty("/chinaBric.properties").getProperty("fgwSendMailMethodName");
	private static final String fgwSendMessageMethodName=MyProperties.loadProperty("/chinaBric.properties").getProperty("fgwSendMessageMethodName");
	private static int FGWSendMsg(String MsgType,String...param){
		Service service=new Service();
		try {
			Call call=(Call) service.createCall();
			call.setTargetEndpointAddress(new URL(fgwWebServiceUrl));
			call.setOperationName(new QName(fgwWebServiceUrl, MsgType));
			Object[] params=null;
			if(MsgType.equals(fgwSendMessageMethodName)){
				params=new Object[]{"guid001",param[0],param[1]};
			}else{
				params=new Object[]{"guid001",param[0],param[1],param[2]};
			}
			String result=(String) call.invoke(params);
			System.out.println("返回值是"+result);
			return 1;
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return 0;
	}
	public static void main(String[] args) {
		FGWSendMsg(fgwSendMessageMethodName, "18515634668","测试发短信");
		FGWSendMsg(fgwSendMailMethodName, "it9210@sina.com","发邮件123456","这里是邮件内容111111");
	}
}
